package main.chapter6

import java.awt.BorderLayout
import java.awt.Dimension
import java.awt.event.ActionEvent
import javax.swing.*

class MainWindow : JFrame() {
    private lateinit var button: JButton
    private lateinit var image: JLabel

    fun init() {
        button = JButton("点击获取图片")
        image = JLabel()
        image.size = Dimension(200, 160)

        contentPane.add(button,BorderLayout.NORTH)
        contentPane.add(image,BorderLayout.CENTER)
    }

    fun onClickButton(listener: (ActionEvent) -> Unit) {
        button.addActionListener(listener)
    }

    fun setLogo(logoData: ByteArray) {
        image.icon = ImageIcon(logoData)
        image.isVisible = true
    }
}